<script setup lang="ts">
import { Handle, Position } from '@vue-flow/core';
import { NIcon } from 'naive-ui';
import { Edit, Share } from '@vicons/carbon';

interface NodeData {
  label: string;
  description?: string;
  isDefault?: boolean;
}

defineProps<{
  id: string;
  data: NodeData;
}>();
</script>

<template>
  <div
    class="mutex-branch-node"
    :class="{ 'default-branch': data.isDefault }"
  >
    <!-- 顶部输入连接点 -->
    <Handle type="target" :position="Position.Top" class="handle" />

    <!-- 条件头部 -->
    <div class="branch-header">
      <div class="branch-title">
        {{ data.label || '条件' }}
      </div>
      <div class="branch-actions">
        <NIcon :size="14" class="share-icon">
          <Share />
        </NIcon>
        <NIcon :size="14" class="edit-icon">
          <Edit />
        </NIcon>
      </div>
    </div>

    <!-- 条件内容 -->
    <div class="branch-body">
      {{ data.description || '点击编辑条件' }}
    </div>

    <!-- 底部输出连接点 -->
    <Handle type="source" :position="Position.Bottom" class="handle" />
  </div>
</template>

<style scoped>
.mutex-branch-node {
  min-width: 200px;
  max-width: 240px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: all 0.2s;
  overflow: visible;
}

.mutex-branch-node.default-branch {
  border-color: #10b981;
}

.mutex-branch-node:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.branch-header {
  background: #10b981;
  color: white;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 6px 6px 0 0;
}

.branch-title {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
}

.branch-actions {
  display: flex;
  gap: 8px;
}

.share-icon,
.edit-icon {
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}

.share-icon:hover,
.edit-icon:hover {
  opacity: 1;
}

.branch-body {
  padding: 14px;
  font-size: 13px;
  color: #6b7280;
  line-height: 1.4;
  min-height: 50px;
}

.handle {
  width: 8px;
  height: 8px;
  background: #10b981;
  border: 2px solid white;
  border-radius: 50%;
}
</style>
